home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / dols.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  2KB  |  86 lines

  1. #include "kiss.h"
  2.  
  3. int dols (Stringstack s)
  4. {
  5.     register int
  6.     i,
  7.     opt;
  8.     LsFlags
  9.     fl = { 0, 0, 0, 0, 0 };
  10.     register int
  11.     ret = 0;
  12.     struct stat
  13.     statbuf;
  14.  
  15.     /* column-wise is default for display, otherwise 1 per line is def */
  16.     if (isatty (STDOUT_FILENO))
  17.     fl.column = 1;
  18.     else
  19.     fl.oneperline = 1;
  20.  
  21.     while ( (opt = getopt (s.nstr, s.str, "hl1CFa")) != -1 )
  22.     switch (opt)
  23.     {
  24.         case 'l':
  25.         fl.longoutput = 1;
  26.         /* fall thru to one per line output */
  27.         case '1':
  28.         fl.oneperline = 1;
  29.         fl.column = 0;
  30.         break;
  31.         case 'C':
  32.         fl.column = 1;
  33.         fl.longoutput = 0;
  34.         fl.oneperline = 0;
  35.         break;
  36.         case 'F':
  37.         fl.listtype = 1;
  38.         break;
  39.         case 'a':
  40.         fl.showall = 1;
  41.         break;
  42.         case 'h':
  43.         default:
  44.         error ("Bad commandline.\n"
  45.                "Usage: %s [-1aCFlh] [files or directories]\n"
  46.                "Where:\n"
  47.                "    -1   one entry per line\n"
  48.                "    -a   show all, includes .*\n"
  49.                "    -C   column-wise listing\n"
  50.                "    -F   append type-character: / for dir,"
  51.                         " = for pipe, @ for link\n"
  52.                "    -l   long listing format\n"
  53.                , progname);
  54.     }
  55.  
  56.     if (s.nstr == optind)
  57.     {
  58.     ret += listdir (".", fl);
  59.     listoutputflush ();
  60.     return (ret);
  61.     }
  62.  
  63.     /* list directories first */
  64.     for (i = optind; i < s.nstr; i++)
  65.     {
  66.     if (stat (s.str [i], &statbuf))
  67.         ret += warning ("can't stat \"%s\"", s.str [i]);
  68.     else if (S_ISDIR (statbuf.st_mode))
  69.     {
  70.         if (s.nstr - optind > 1)
  71.         printf ("%s:\n", s.str [i]);
  72.         ret += listdir (s.str [i], fl);
  73.         listoutputflush ();
  74.     }
  75.     }
  76.     
  77.     /* list ordinary files next */
  78.     for (i = optind; i < s.nstr; i++)
  79.     if (! stat (s.str [i], &statbuf) && ! S_ISDIR (statbuf.st_mode))
  80.         ret += listfile (s.str [i], fl);
  81.  
  82.     listoutputflush ();
  83.     
  84.     return (ret);
  85. }
  86.